from django import forms
from django.contrib.auth.models import User

from projects.models import Project

class ProjectForm(forms.ModelForm):
    """
    ModelForm for a Project, used for creation and editing
    """
    title = forms.CharField(min_length=3, max_length=50)
    
    class Meta:
        model = Project
        exclude = ('members',)

class MemberQuickAdd(forms.Form):
    user = forms.CharField() 

    def clean_user(self):
        username = self.cleaned_data['user']
        try:
            user = User.objects.get(username=username)
            return user
        except User.DoesNotExist:
            raise forms.ValidationError(u'That user does not exist')